<%@page import="com.sample.portlet.library.service.BookLocalServiceUtil"%>
<%@page import="com.sample.portlet.library.model.Book"%>
<%@include file="/jsp/init.jsp"%>
<%
PortletURL addURL = renderResponse.createActionURL();
PortletURL displayURL = renderResponse.createRenderURL();
%>
<h1>Add Book</h1>
<liferay-ui:success key="bookAdded"
	message="Your book has been added sucessfully!"></liferay-ui:success>

<aui:form name="fm" action="<%= addURL %>" method="Post">
	<aui:input name="bookId" type="hidden" />
	 Book Name:
	  	<aui:input label="" name="bookName" id="bookName" type="String" />
	<div id="required">
		<label class="errorMsg">* Name is Required</label>
	</div>
	<aui:input name="version" id="version" type="double" />
	<aui:input name="price" type="double" />
	<div id="requiredPrice">
		<label class="errorMsg">* Price is Required</label>
	</div>
	<aui:input name="author" type="String" />
	<aui:button name="subhmit" type="submit" value="subhmit"
		onClick="return f1();" />
</aui:form>

<%-- <a href="<%= displayURL %>" >List All Book</a> --%>

<liferay-ui:search-container delta="5" emptyResultsMessage="No Book Found">
	<liferay-ui:search-container-results
		results="<%= BookLocalServiceUtil.getBooks(searchContainer.getStart(), searchContainer.getEnd()) %>"
		total="<%=BookLocalServiceUtil.getBooksCount() %>" />
	
	<liferay-ui:search-container-row className="com.sample.portlet.library.model.Book"
		keyProperty="bookId" modelVar="book">
		<liferay-ui:search-container-column-text name="name"  value="<%= book.getBookname() %>" />
		<liferay-ui:search-container-column-text name="version" property="version"/>
		<liferay-ui:search-container-column-text name="price" property="price"/>
		<liferay-ui:search-container-column-text name="author" property="author"/>
	</liferay-ui:search-container-row>
	<liferay-ui:search-iterator/>
</liferay-ui:search-container>
<script>
jQuery('#required').hide();
jQuery('#requiredPrice').hide();

function f1(){
	var name = jQuery('#<portlet:namespace/>bookName').val();
	var price = jQuery('#<portlet:namespace/>price').val();
	
	if(name==""){
		jQuery('#required').show(1000);
		return false;	
	}
	if(price==""){
		jQuery('#requiredPrice').show(1000);
		return false;
	}
	return true;
}
</script>
